package com.andengine.editor;

import java.awt.FontMetrics;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;

/**
 * @author sad
 */
public class Utils {

    public static boolean intersectRect(int left1, int right1, int top1, int bottom1,
            int left2, int right2, int top2, int bottom2) {
        return !(left2 > right1
                || right2 < left1
                || top2 > bottom1
                || bottom2 < top1);
    }
    
    public static void drawStringInCenterOfRect(String str, int x, int y, int width, int height, Graphics g, JComponent c){
        FontMetrics metrics = c.getFontMetrics(c.getFont());
        int strWidth = SwingUtilities.computeStringWidth(metrics, str);
        int strHeight = metrics.getHeight();
        g.drawString(str, (int) (width / 2 - strWidth / 2), height/2-strHeight/2);
    }
}
